package com.dongdongshop.service.impl;

import com.dongdongshop.mapper.TbItemMapper;
import com.dongdongshop.pojo.TbItem;
import com.dongdongshop.pojo.TbItemExample;
import com.dongdongshop.service.ItemService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
import java.util.List;

@Service
@DubboService
public class ItemServiceImpl implements ItemService {

    @Resource
    private TbItemMapper itemMapper;

    @Override
    public int addItem(TbItem item) {
        LocalDateTime localDateTime = LocalDateTime.now();
        Date date = Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
        item.setStatus("2");
        item.setCreateTime(date);
        return itemMapper.insertSelective(item);
    }

    @Override
    public int deleteBatch(Long[] ids) {
        return itemMapper.deleteBatch(ids);
    }

    @Override
    public List<TbItem> selectByGoodsId(Long goodsId) {
        TbItemExample example = new TbItemExample();
        TbItemExample.Criteria criteria = example.createCriteria();
        criteria.andStatusEqualTo("1");
        criteria.andGoodsIdEqualTo(goodsId);
        return itemMapper.selectByExample(example);
    }

    @Override
    public TbItem selectById(Long skuId) {
        return itemMapper.selectByPrimaryKey(skuId);
    }


}
